<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      brandList: [],
      carList: [],
      show: false
    }
  },
  created() {
    this.brandList = []
    this.$api.getBrand().then(res => {
      if (res.success) {
        const obj = {};
        res.data.forEach(item => {
          if (obj[item.type]) { // obj['A'] = [item]
            obj[item.type].push(item)
          } else {
          }
        })
        Object.keys(obj).forEach(item => {
          this.brandList.push({
            type: "title",
            title: item
          })
          obj[item].forEach(item2 => {
            this.brandList.push(item2)
          })
        })
      }
    })
  },
  methods: {
    openRightPopup(id) {
      this.show = true;
      this.$api.getCarList(id).then(res => {
        if (res.success) {
          const obj = {};
          res.data.forEach(item => {
            if (obj[item.type]) { // obj['A'] = [item]
              obj[item.type].push(item)
            } else {
              obj[item.type] = [item]
            }
          })
          Object.keys(obj).forEach(item => {
            this.carList.push({
              type: "title",
              title: item
            })
            obj[item].forEach(item2 => {
              this.carList.push(item2)
            })
          })
        }
      })
    }
  }
}
</script>

<style>
</style>